package com.leyou.item.mapper;

import com.leyou.item.pojo.Brand;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author CHERRY
 * @date 2018-09-02-19:55
 */
public interface BrandMapper extends Mapper<Brand>,SelectByIdListMapper<Brand,Long> {

    /**
     * 新增分类和品牌中间表
     *
     * @param cid
     * @param pid
     */
    @Insert("INSERT INTO tb_category_brand VALUES(#{cid},#{pid})")
    void insertCategoryBrand(@Param("cid") Long cid, @Param("pid") Long pid);

    /**
     * 更新品牌信息
     *
     * @param brand
     */
    @Update("UPDATE tb_brand SET name=#{name},image=#{image},letter=#{letter} WHERE id = #{id}")
    void updateBrand(Brand brand);

    /**
     * 根据品牌id删除所属分类
     *
     * @param bid
     */
    @Delete("DELETE FROM tb_category_brand WHERE brand_id = #{bid}")
    void deleteCategoryBid(@Param("bid") Long bid);

    /**
     * 根据类目Id查询品牌数据
     *
     * @param cid
     * @return
     */
    @Select("SELECT b.* FROM tb_brand AS b,tb_category_brand WHERE category_id = #{cid} AND brand_id = b.id ")
    List<Brand> queryBrandByCid(@Param("cid") Long cid);
}
